package com.example.admin.controller;

import com.example.admin.model.Person;
import com.example.admin.result.ResponseResult;
import com.example.admin.service.ExampleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/example")
public class ExampleContrller {

    @Autowired
    ExampleService exampleService;

    @RequestMapping("/producerKafkaExample")
    public ResponseResult<String> producerKafkaExample(){
        return exampleService.producerKafkaExample();
    }

    @RequestMapping(value = "/producerRedisExample", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResponseResult<String> producerRedisExample(@RequestBody List<Person> personList) {
        return exampleService.producerRedisExample(personList);
    }

    @RequestMapping(value = "/saveSeataAndRedisExample", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResponseResult<String> saveSeataAndRedisExample(@RequestBody List<Person> personList) {
        return exampleService.saveSeataAndRedisExample(personList);
    }

    @RequestMapping(value = "/savePersonExample", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResponseResult<String> savePersonExample(@RequestBody List<Person> personList) {
        return exampleService.savePersonExample(personList);
    }

    @RequestMapping(value = "/queryPersonExample", method = RequestMethod.GET)
    public ResponseResult<List<Person>> queryPersonExample(){
        return exampleService.queryPersonExample();
    }

}
